/*
 * File      : led.c
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2010, RT-Thread Development Team
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rt-thread.org/license/LICENSE
 *
 * Change Logs:
 * Date           Author       Notes
 * 2010-08-28     Yi.Qiu       the first version
 */
#include <rtthread.h>
#include <lm3s8962.h>

static rt_uint8_t led_inited = 0;
void rt_hw_led_init(void)
{
	int dummy;

	if (led_inited == 0)
	{
	    /* Enable the GPIO port that is used for the on-board LED. */
	    SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOF;
	
	    /* Do a dummy read to insert a few cycles after enabling the peripheral. */
	    dummy = SYSCTL_RCGC2_R;
	
	    /* Enable the GPIO pin for the LED (PF0).  Set the direction as output, and
	    	enable the GPIO pin for digital function. */
	    GPIO_PORTF_DIR_R = 0x01;
	    GPIO_PORTF_DEN_R = 0x01;

		led_inited = 1;
	}
}

void rt_hw_led_on(void)
{
	GPIO_PORTF_DATA_R |= 0x01;
}

void rt_hw_led_off(void)
{
	GPIO_PORTF_DATA_R &= ~0x01;
}

#ifdef RT_USING_FINSH
#include <finsh.h>
void led(rt_uint32_t value)
{
    /* init led configuration if it's not inited. */
    if (!led_inited)
        rt_hw_led_init();

    /* set led status */
    switch (value)
    {
    case 0:
        rt_hw_led_off();
        break;
    case 1:
        rt_hw_led_on();
        break;
    default:
        break;
    }
}
FINSH_FUNCTION_EXPORT(led, set led on(1) or off(0))
#endif
